package com.xq.response;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.xq.code.ResultCode02;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 公共返回结果类
 *
 * @author qiang ge
 */
@Data
public class Result02<T> implements Serializable {
    @ApiModelProperty(value = "是否成功")
    private Boolean success;

    @ApiModelProperty(value = "返回码")
    private Integer code;

    @ApiModelProperty(value = "服务器当前时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime dateTime = LocalDateTime.now();

    @ApiModelProperty(value = "返回消息")
    private String message;

    @ApiModelProperty(value = "返回数据")
    private T data;

    public static Result02 success() {
        Result02 Result02 = new Result02();
        Result02.success = ResultCode02.SUCCESS.getSuccess();
        Result02.message = ResultCode02.SUCCESS.getMessage();
        Result02.code = ResultCode02.SUCCESS.getCode();
        return Result02;
    }

    public static Result02 fail() {
        Result02 Result02 = new Result02();
        Result02.success = ResultCode02.FAIL.getSuccess();
        Result02.code = ResultCode02.FAIL.getCode();
        Result02.message = ResultCode02.FAIL.getMessage();
        return Result02;
    }

    public Result02 data(T data) {
        this.data = data;
        return this;
    }

    public Result02 message(String message) {
        this.message = message;
        return this;
    }
}
